#pragma once
#include <DirectXMath.h>
#include "Constants.h"

// forward declaration
class FourierCalculator;

class Fourier
{
	DirectX::XMVECTOR mA[kMaxDegree];
	DirectX::XMVECTOR mB[kMaxDegree];
	DirectX::XMVECTOR mA0;
	int mDegree;
	friend class FourierCalculator;
public:

	COLORREF ColorAtAngle(float angle) const;
	DirectX::XMVECTOR ColorComponentsAtAngle(float angle) const;
	int GetDegree() const;

	DirectX::XMVECTOR GetConstantCoefficient() const;

	// these two functions does not account for mA0.
	DirectX::XMVECTOR IntegralWithoutConstantAtAngle(float angle) const;
	DirectX::XMVECTOR ColorComponentsWithoutConstantAtAngle(float angle) const;

	DirectX::XMVECTOR DerivativeAtAngle(float angle) const;
	float SquareOfDerivativeAtAngle(float angle) const;

	float IntegralOfSquareAroundCircle() const;
};



class FourierCalculator
{
	float mCosines[2 * kMaxDegree + 1];
	float mSines[2 * kMaxDegree + 1];
	int mDegree;

	// mNumberOfIterations = 2 * mDegree + 1, it is a number of sample points
	// for calculation Fourier coefficients
	int mNumberOfIterations;

	// used in steps for calculation Fourier object
	int mCurrentIterationIndex;

public:
	static const int kInitialValueForIndex = -1;

	FourierCalculator();

	void SetDegree(int);

	void BeginUpdatingFourier(Fourier& outFourier);
	void EndUpdatingFourier(Fourier& outFourier);
	bool GetNextPoint(float& outX, float& outY);
	void AddColorToFourier(DirectX::XMVECTOR color, Fourier& ioFourier);
};